<?php

class PluginPropel
{
	
	public function start() 
	{
		$modelDir = realpath(PROPEL_LIB_PATH . '/classes');
		$propelPath = realpath(PROPEL_LIB_PATH . '/propel');
		$propelOmPath = realpath($propelPath . '/om');
		$propelMapPath = realpath($propelPath . '/map');
		
		set_include_path(implode(PATH_SEPARATOR, array(
		    $modelDir,
		    $propelPath,
		    get_include_path(),
		)));
		
		// register model autloader
		spl_autoload_register(array($this, 'modelAutoload'));
		
		// initialize propel
		require_once('Propel.php');
		Propel::init(PROPEL_LIB_PATH .'/conf/-conf.php');
	}
	
	public function modelAutoload($className) 
	{
		$path = realpath(PROPEL_LIB_PATH . '/classes');
		
		$propelPath = realpath(PROPEL_LIB_PATH . '/propel');
		$propelOmPath = realpath($propelPath . '/om');
		$propelMapPath = realpath($propelPath . '/map');
		
		$paths = array(
			$path.'/'.$className.'.php',
			$path.'/om/'.$className.'.php', 
			$propelOmPath.'/'.$className.'.php',
			$propelMapPath.'/'.$className.'.php'
		);
		
		foreach($paths as $modelPath) {
			if (file_exists($modelPath)) {
				require_once($modelPath);
				return;
			}
		}
	}
	
}

?>